package com.wwz.leetcode;

import java.util.ArrayList;
import java.util.List;
/**
 * @Description: 中序遍历  左根右
 * @create: 2022-02-07 10:36:41
 * @author:wwz
 */
public class LeetCode94 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> resList = new ArrayList<>();
        inorder(root,resList);
        return resList;
    }
    public static void inorder(TreeNode root,List<Integer> resList){
        if(root==null){
            return;
        }
        inorder(root.left,resList);
        resList.add(root.val);
        inorder(root.right,resList);
    }

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1, null, new TreeNode(2, new TreeNode(3,null,null), null));
        List<Integer> list = inorderTraversal(treeNode);
        System.out.println(list);
    }
}
